home *** CD-ROM | disk | FTP | other *** search
- Path: in2.uu.net!csnews!boulder!usenet
- From: Edmond <underwoe@Colorado.Edu>
- Newsgroups: comp.lang.c++,comp.os.ms-windows.programmer.win32
- Subject: Re: VC++ 4.0 memory allocation slower than in 2.x!!!
- Date: Mon, 01 Apr 1996 15:04:43 -0700
- Organization: CNS
- Message-ID: <316052FB.2014@Colorado.Edu>
- References: <alanDozpsy.Kn6@netcom.com> <315C4DA0.30C@Bentley.com> <316049E7.739D@sdt.com>
- NNTP-Posting-Host: samiam.colorado.edu
- Mime-Version: 1.0
- Content-Type: text/plain; charset=iso-8859-1
- Content-Transfer-Encoding: quoted-printable
- NNTP-Posting-User: underwoe
- X-Mailer: Mozilla 2.0 (X11; I; SunOS 5.4 sun4m)
-
- Larry Baker wrote:
- > =
-
-
- > - VirtualAlloc operates directly on the virtual memory tables; hence,
- > it allocates memory pages at a time, where you specify the address
- > range to allocate, and has options for locking them in memory, etc.
- > But explicit management of the memory provided (suballocation) must
- > be done manually. To those who can check: is the 2.0 *alloc thread-
- > safe?
- > =
-
- > - GlobalAlloc operates on 'the heap.' It appears to be a legacy
- > interface to the old Win16/Win32s interface(s). There is no mention
- > of thread-safeness.
- > =
-
-
- This call is outdated and shouldn't be used anymore. I imagine that the
- kernel turns it into HeapAlloc (or the runtime library). =
-
-
- > - HeapAlloc, by default, performs mutual exclusion on its heap
- > object argument. This incurrs an unnecessary performance penalty
- > if you're a single-threaded app and can be avoided if you allocate
- > per-thread heaps if your a multi-threaded app. Otherwise, it's
- > necessary, either at the OS or at the runtime level. See the excerpt
- > from my Win32 Online Help, below.
- > =
-
- > - VirtualAlloc appears to be the low-level interface to the virtual
- > memory subsystem. GlobalAlloc appears to be a general heap manager,
- > and does not differentiate between the old local or global heaps.
- > HeapAlloc appears to be a complete generalization of heap management,
- > accounting for thread-safeness at the OS level.
- > =
-
- > - This sort of thing can't help but bias benchmarks, as evidenced
- > by last months' Byte Magazine on the subject. They discovered a
- > similar performance sensitivity to malloc: sometimes (at least, with
- > MS 4.x) it returns byte-aligned allocations, rather than word
- > aligned. This causes roughly a 50% (20%?) performance penalty on the
- > Pentium for misaligned 32-bit or greater reads, as the hardware has
- > to do some monkey business for things like floats, doubles, ints...
- > =
-
-
- This is their (Byte's) own blunder that they made a bigger deal of than
- it should have been. Most compilers stick with MS's routine for memory
- allocation so I'd imagine that all of them show this behavior.
-
- > - It would be useful if someone with 4.x could check their online
- > reference materials to see if they can illuminate the subject further.
- > =
-
- > From the Win32 Online Help accompnaying my Borland C++ v4.52:
- > =
-
-
- Check out Jeffrey Richter's Advanced Windows programming. I think it's
- somewhat better than the old, outdated, Borland guide to poor Win32
- programming.
-
-
- > =B7 The process has only one thread.
- > =B7 The process has multiple threads, but only one thread calls the=
-
- > heap functions for a specific heap.
- > =B7 The process has multiple threads, and the application provides
- > its own mechanism for mutual exclusion to a specific heap.
- > =
-
-
- Other than it's very good exception handling, I don't see any reason to
- use HeapAlloc()'s over VirtualAlloc()'s (BTW: HeapAlloc supposedly
- defaults to VirtualAlloc when you have run out of physical memory). Why
- would different threads be allocating/removing the same block of memory
- anyway. That would pose synchronization problems that would be sure to
- cost your application a lot of unnecessary time wasting. I would simply
- use the VirtualAlloc routine (with some inherent calls to _heapmin()
- here and there) giving the job of allocating and deallocating to the
- main application thread and using the HeapDestroy(GetProcessHeap()...)
- upon program removal. I think one would have safer, faster, memory
- allocation routines this way. =
-
-
- -- =
-
- Edmond Underwood
- email: underwoe@Colorado.Edu
- Bench32 for Windows NT and Windows 95
- http://www.rmii.com/~underwoe/bench32.html
-